<div class="form-group clearfix">
  <div class="form-inline pull-left">
    <button type="button" class="btn btn-default" (click)="addModal.show()">新增类型</button>
  </div>
  <div class="form-inline pull-right">
    <input type="text" class="form-control" placeholder="类型名称" name="searchData" [(ngModel)]="searchData">
    <button class="btn btn-default" (click)="search()">搜索</button>
    <button class="btn btn-default" (click)="reset()">重置</button>
  </div>
</div>
<div>
  <table class="table">
    <thead>
    <tr>
      <th>ID</th>
      <th>名称</th>
      <th>描述</th>
      <th>备注</th>
      <th>创建时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
      <tr *ngFor="let item of dataList">
        <td>{{item.id}}</td>
        <td>{{item.name}}</td>
        <td>{{item.describe}}</td>
        <td>{{item.remark||''}}</td>
        <td>{{item.created_at}}</td>
        <td>
          <a href="javascript:;" (click)="editType(item.id,item.name,item.describe,item.remark)">编辑</a>-
          <a href="javascript:;" (click)="delType(item.id)">删除</a>
        </td>
      </tr>
    </tbody>
  </table>
  <div class="text-center">
    <pagination (pageChanged)="pageChanged($event)" [totalItems]="totalItems" [itemsPerPage]="itemsPerPage" [(ngModel)]="currentPage" [maxSize]="5"
                previousText="&lsaquo;" nextText="&rsaquo;" firstText="&laquo;" lastText="&raquo;" [boundaryLinks]="true" class="pagination-sm"></pagination>
  </div>
</div>

<app-notification [type]="type" [message]="message" [isShow]="isShow" (promptIsShow)="promptIsShow($event)"></app-notification>

<!-- 添加模板类型 -->
<div class="modal fade" bsModal #addModal="bs-modal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <form #addTypeForm="ngForm">
        <div class="modal-header">
          <h4 class="modal-title pull-left">预览</h4>
          <button type="button" class="close pull-right" aria-label="Close" (click)="addModal.hide()">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="form-group clearfix">
            <label class="col-md-2">类型名称</label>
            <div class="col-md-8">
              <input type="text" class="form-control" required name="name" #name="ngModel" [(ngModel)]="addTemplateType.name">
              <p [hidden]="name.pristine || name.valid" class="alert alert-danger">类型名称不能为空!</p>
            </div>
          </div>
          <div class="form-group clearfix">
            <label class="col-md-2">描述</label>
            <div class="col-md-8">
              <input type="text" class="form-control" name="describe" [(ngModel)]="addTemplateType.describe">
            </div>
          </div>
          <div class="form-group clearfix">
            <label class="col-md-2">标记</label>
            <div class="col-md-8">
              <input type="text" class="form-control" name="remark" [(ngModel)]="addTemplateType.remark">
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-default" type="button" (click)="addModal.hide()">取消</button>
          <button class="btn btn-success" type="submit" [disabled]="!addTypeForm.form.valid" (click)="addTypeSubmit()">确定</button>
        </div>
      </form>
    </div>
  </div>
</div>

<!-- 编辑模板类型 -->
<div class="modal fade" bsModal #editModal="bs-modal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <form #editTypeForm="ngForm">
        <div class="modal-header">
          <h4 class="modal-title pull-left">预览</h4>
          <button type="button" class="close pull-right" aria-label="Close" (click)="editModal.hide()">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          <div class="form-group clearfix">
            <label class="col-md-2">类型名称</label>
            <div class="col-md-8">
              <input type="text" class="form-control" required name="name" #name="ngModel" [(ngModel)]="editTemplateType.name">
              <p [hidden]="name.pristine || name.valid" class="alert alert-danger">类型名称不能为空!</p>
            </div>
          </div>
          <div class="form-group clearfix">
            <label class="col-md-2">描述</label>
            <div class="col-md-8">
              <input type="text" class="form-control" name="describe" [(ngModel)]="editTemplateType.describe">
            </div>
          </div>
          <div class="form-group clearfix">
            <label class="col-md-2">标记</label>
            <div class="col-md-8">
              <input type="text" class="form-control" name="remark" [(ngModel)]="editTemplateType.remark">
            </div>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-default" type="button" (click)="editModal.hide()">取消</button>
          <button class="btn btn-success" type="submit" [disabled]="!editTypeForm.form.valid" (click)="editTypeSubmit()">确定</button>
        </div>
      </form>
    </div>
  </div>
</div>

<!-- 是否确认删除弹框 -->
<div class="modal fade" bsModal #delModal="bs-modal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title pull-left">提示</h4>
        <button type="button" class="close pull-right" aria-label="Close" (click)="delModal.hide()">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body text-center">
        是否确认删除
      </div>
      <div class="modal-footer mt20">
        <button class="btn btn-default btn-md-long" type="button" (click)="delModal.hide()">取消</button>
        <button class="btn btn-success btn-md-long" type="submit" (click)="delTypeSubmit()">确定</button>
      </div>
    </div>
  </div>
</div>
